<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        body {
            background-color: skyblue;
        }

        img {
            width: 100px;
            height: 100px;
        }
    </style>
</head>

<body>
    <script>
        // 代理类实现图片loading
        function MyImage(src) {
            // 创建节点
            this.oImg = document.createElement("img");
            // 节点上树
            document.body.appendChild(this.oImg);
        }
        MyImage.prototype.setSrc = function (src) {
            this.oImg.src = src;
        };
        // 代理类
        function MyImageProxy(src) {
            this.myImage = new MyImage();
            this.myImage.setSrc("./images/loading.gif");

            // image相当于一个钩子
            var image = new Image();
            image.src = src;
            var that = this;
            image.onload = function(){
                that.myImage.setSrc(src)
            }
        }
        new MyImageProxy("./images/0.jpg")
        new MyImageProxy("./images/1.jpg")
        new MyImageProxy("./images/2.jpg");
    </script>
</body>

</html>